﻿<%@ WebHandler Language="C#" Class="validate" %>

using System;
using System.Web;
using Liger.Common;
using EasyFMS.Model;
using EasyFMS.Common;
using Liger.Data;
using System.Linq;
using Liger.Data.Linq;
using System.Web.SessionState;
using EasyFMS.Service;

/// <summary>
/// 前台数据验证入口
/// </summary>
public class validate : IHttpHandler, IRequiresSessionState
{
    //private DbContext DB = DbHelper.Db;
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        try
        {
            switch (context.Request.Params["Action"])
            {
                case "Login":
                    ValidateLogin();
                    break;
                default:
                    context.Response.Write("false");
                    break;
            }
        } 
        catch (Exception err)
        {
            context.Response.Write("false");
        }
        context.Response.End();
    }
    
    //void ValidateExist()
    //{
    //    var context = System.Web.HttpContext.Current;
    //    string view = context.Request.Params["View"].ToLower(); 
    //    switch (view)
    //    {
    //        case "user":
    //            string username = context.Request.Params["LoginName"]; 
    //            var existUser = DB.Query<CFUser>().Where(c => c.LoginName == username).Any();
    //            context.Response.Write(existUser ? "false" : "true");
    //            break;
    //        case "role":
    //            string rolename = context.Request.Params["RoleName"];
    //            var existRole = DB.Query<CFRole>().Where(c => c.RoleName == rolename).Any();
    //            context.Response.Write(existRole ? "false" : "true");
    //            break;
    //        case "menu":
    //            string menuno = context.Request.Params["MenuNo"];
    //            var existMenu = DB.Query<SysMenu>().Where(c => c.MenuNo == menuno).Any();
    //            context.Response.Write(existMenu ? "false" : "true");
    //            break;
    //        case "dataprivilege":
    //            string DataPrivilegeView = context.Request.Params["DataPrivilegeView"];
    //            var existDataPrivilege = DB.Query<CFDataPrivilege>().Where(c => c.DataPrivilegeView == DataPrivilegeView).Any();
    //            context.Response.Write(existDataPrivilege ? "false" : "true");
    //            break;
    //    }  
    //}

    void ValidateLogin()
    {
        var context = System.Web.HttpContext.Current;
        string username = context.Request.Params["username"];
        string password = context.Request.Params["password"];
        context.Response.Write(SystemService.UserLogin(username, password) ? "true" : "false");
    }
    
    public bool IsReusable {
        get {
            return false;
        }
    }

}